package com.bijiawang.user.controller;

import com.bijiawang.user.bean.Userinfo;
import com.bijiawang.user.service.EmailService;
import com.bijiawang.user.service.UserinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.UnsupportedEncodingException;

@Controller
public class SendEmailController {

    @Autowired
    UserinfoService userinfoService;

    @Autowired
    EmailService emailService;

    @ResponseBody
    @GetMapping("/sendEmail/{number}")
    public String sendEmail(@PathVariable("number") String number) throws UnsupportedEncodingException {
        Userinfo user = userinfoService.getUserinfoByPhoneNumber(number);
        String email = user.getEmail();
        emailService.sendEmail(email);
        return email;
    }
}
